public class Test{
    public static void main(String[] args) {
        boolean ret = isHappy(19);
        System.out.println(ret);
    }

    //快乐数
        public static boolean isHappy(int n) {
            int slow = n;
            int fast = quadraticSum(n);
            while(slow != fast){
                slow = quadraticSum(slow);
                fast = quadraticSum(quadraticSum(fast));
            }
            return (slow == 1);
        }
        private static int quadraticSum(int n){
            int sum = 0;
            int tmp = n;
            while(n != 0){
                sum += (n % 10) * (n % 10);
                n /= 10;
            }
            return sum;
        }
}